$(function () {
    var currentPage = 1
    var pageSize = 5

    function render() {
        $.ajax({
            url: '/user/queryUser',
            data: {
                page: currentPage,
                pageSize: pageSize
            },
            dataType: 'json',
            success: (info) => {
                // console.log(info);
                $('tbody').html(template('tmp', info))
                pageoff(info.total)
            }

        })
    }
    render()


    function pageoff(total) {
        $("#pagintor").bootstrapPaginator({
            bootstrapMajorVersion: 3,//默认是2，如果是bootstrap3版本，这个参数必填
            currentPage: currentPage,//当前页
            totalPages: Math.ceil(total / pageSize),//总页数
            size: "small",//设置控件的大小，mini, small, normal,large
            onPageClicked: function (event, originalEvent, type, page) {
                //为按钮绑定点击事件 page:当前点击的按钮值
                currentPage = page
                render()
            }
        });
    }

    // 按钮操作
    var ids = null
    var isDelete = null
    $('tbody').on('click' , '.btn' , function() {
        $('.modal-on-off').modal('show')
        ids = $(this).parent().attr('id')
        isDelete = $(this).hasClass('btn-danger')? 0 :1
    })

    $('.btn-yes').on('click' , function() {
        $.ajax({
            url:'/user/updateUser',
            type:'post',
            data:{
                id : ids,
                isDelete :isDelete
            },
            success:(info)=> {
                // console.log(info);
                if(info.success) {
                    $('.modal-on-off').modal('hide') 
                    render()
                }
                
            }
        })
    })



})